package com.ketangpai.service.impl;

import com.ketangpai.entity.response.BaseResponse;
import com.ketangpai.entity.response.Course;
import com.ketangpai.entity.response.TwoCourses;
import com.ketangpai.mapper.StudentMapper;
import com.ketangpai.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jiahao
 * @date 2024/2/18 15:19
 */
@Service
public class StudentService implements com.ketangpai.service.StudentService {
    @Autowired
    StudentMapper studentMapper;
    @Override
    @Transactional
    public BaseResponse<TwoCourses> getCourses(int account) {
        BaseResponse<TwoCourses> baseResponse = new BaseResponse<>();
        TwoCourses twoCourses = new TwoCourses();
        try {
            List<String> learnAccounts = studentMapper.getAccount(account, "1");
            List<String> teachAccounts = studentMapper.getAccount(account, "0");
            List<Course> learnCourses = studentMapper.getCourses(learnAccounts);
            List<Course> teachCourses = studentMapper.getCourses(teachAccounts);
            twoCourses.setLearnCourses(learnCourses);
            twoCourses.setTeachCourses(teachCourses);
            baseResponse.setStatus("success");
            baseResponse.setMessage("success");
            baseResponse.setData(twoCourses);
            return baseResponse;
        } catch (Exception e) {
            e.printStackTrace();
            baseResponse.setStatus("failed");
            baseResponse.setMessage(e.getMessage());
            return baseResponse;
        }
    }
}
